package org.esisar.controller.address;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.esisar.exceptions.AddressExistException;

public class AddressController extends HttpServlet {
	
	public void doGet(HttpServletRequest req, HttpServletResponse res) 
			throws ServletException, IOException{

		res.setContentType("text/html");

		if (req.getParameter("address") != null) {
			try {
				
				AddressUtils.createAddress(req);
				req.getRequestDispatcher("User/panel.jsp").forward(req, res);
			
			}catch (AddressExistException e) {
				req.setAttribute("message", "Address already exists");
				req.getRequestDispatcher("User/panel.jsp").forward(req, res);
				e.printStackTrace();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}	
}
